package com.yunhuakeji.wddx.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * @author FuWaer
 * @version 1.0
 */
public class DataTable {
	
	public DataTable(DataRow[] rows)
	{
		Rows = rows.clone();
	}
	
	public DataTable()
	{
		
	}
	
	public void AddRow(DataRow row)
	{
		DataRow[] _rows = Rows.clone();
		this.Rows = null;
		this.Rows = new DataRow[_rows.length+1];
		for(int i=0;i<_rows.length;i++)
		{
			this.Rows[i] = _rows[i];
		}
		this.Rows[this.Rows.length-1] = row;
		_rows = null;
	}
	
	public DataRow[] Rows = new DataRow[0];
	
	public List<Map<String,Object>> TransationToList(DataTable dt)
	{
		List<Map<String,Object>> maplist= new ArrayList<Map<String,Object>>();
		for (int i = 0; i < dt.Rows.length; i++) {
			Map<String, Object> map= new HashMap<String, Object>();
			for (int j = 0; j < dt.Rows[i].Columns.length; j++) {
				map.put(dt.Rows[i].Columns[j].colName, dt.Rows[i].Columns[j].colValue);
			}
			maplist.add(map);
		}
		return maplist;
	}
	
	public List<Map<String,Object>> TransationToListToLowerCase(DataTable dt)
	{
		List<Map<String,Object>> maplist= new ArrayList<Map<String,Object>>();
		for (int i = 0; i < dt.Rows.length; i++) {
			Map<String, Object> map= new HashMap<String, Object>();
			for (int j = 0; j < dt.Rows[i].Columns.length; j++) {
				map.put(dt.Rows[i].Columns[j].colName.toLowerCase(), dt.Rows[i].Columns[j].colValue);
			}
			maplist.add(map);
		}
		return maplist;
	}
	
}
